package com.taojin.shoppinginterest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.taojin.shoppinginterest.R;
import com.taojin.shoppinginterest.bean.SpecialList;
import com.taojin.shoppinginterest.utils.BitmapHelper;

import java.util.List;

/**
 * Created by T400 on 15-5-12.
 */
public class SubjectAdapter extends AppAdapter<SpecialList> {
    private BitmapUtils bitmapUtils;
    public SubjectAdapter(List<SpecialList> list, Context context) {
        super(list, context);
        bitmapUtils = BitmapHelper.getInstance().getBitmapUtils(context, R.mipmap.icon, R.mipmap.icon);
    }



    @Override
    public View createItemView(int position, View convertView, ViewGroup parent) {

        ViewHolder vh;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.fragment_home_special_child_item,parent,false);
            vh=new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh= (ViewHolder) convertView.getTag();
        }

        vh.tvTime.setText(list.get(position).getTime());
        int size=list.get(position).getSub().size();
        for(int i=0;i<size;i++){
            vh.tvAdvice.setText(list.get(position).getSub().get(i).getTitle());
            vh.tvName.setText(list.get(position).getSub().get(i).getCate());
            vh.tvBrowser.setText("浏览"+list.get(position).getSub().get(i).getView_num());
            bitmapUtils.display(vh.imageViewSubject,list.get(position).getSub().get(i).getImg_url());
        }
        return convertView;
    }

    public class ViewHolder {
        @ViewInject(R.id.fragment_home_special_child_item_time)
        private TextView tvTime;
        @ViewInject(R.id.fragment_home_special_child_item_advice)
        private TextView tvAdvice;
        @ViewInject(R.id.fragment_home_special_child_item_image)
        private ImageView imageViewSubject;
        @ViewInject(R.id.fragment_home_special_child_item_name)
        private TextView tvName;
        @ViewInject(R.id.fragment_home_special_child_item_browse)
        private TextView tvBrowser;
        public ViewHolder(View convertView) {
            ViewUtils.inject(this, convertView);
        }
    }
}
